package com.crazy.bookstore.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.crazy.bookstore.entity.Category;
import com.crazy.bookstore.mapper.CategoryMapper;
import com.crazy.bookstore.service.CategoryService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 卢辉宇
 * @date: 2022/12/25 20:33
 * @description:
 */
@Service
//此类默认不开启事务
@Transactional(propagation = Propagation.NOT_SUPPORTED,readOnly = true)
public class CategoryServiceImpl implements CategoryService {
    @Resource
    private CategoryMapper categoryMapper;

    /**
     * 查找全部目录方法
     * @return
     */
    @Override
    public List<Category> selectAll(){

        /*实例化一个查询对象*/
        QueryWrapper wrapper = new QueryWrapper();
        /*按照category_id升序排序*/
        wrapper.orderByAsc("category_id");
        //直接调用mybatisPlus封装好的方法
        List<Category> categories = categoryMapper.selectList(wrapper);

        return categories;
    }
}
